/*
 *  作业1
 */
package com.stage_1.module_4;


public class Worker {
    private String name;
    private int age;

    public Worker() {
    }

    public Worker(String name, int age) throws AgeException, NameException {
        setName(name);
        setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) throws NameException {
        if(name != null && name !="") {
            this.name = name;
        }else{
            throw new NameException("空异常！");
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if(age >= 18 && age <= 150) {
            this.age = age;
        }else{
            throw new AgeException("年龄异常！");
        }
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
